package com.shop2cn.iapi.wxcomponent.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.shop2cn.iapi.wxcomponent.parameter.AppStatusEnum;
import com.shop2cn.iapi.wxcomponent.parameter.GetMchAppListBean;
import com.shop2cn.iapi.wxcomponent.parameter.PayChannelStatusEnum;
import com.shop2cn.iapi.wxcomponent.service.GetMchAppListCall;
import com.ymatou.iapi.captcha.parameter.GetValidateCodeBean;
import com.ymatou.iapi.captcha.service.GetValidateCodeCall;
import com.ymatou.iapi.dguser.parameter.CreateUserBackBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.parameter.UserDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.ValidateCodeServiceV2;
import com.ymttest.business.service.WxComponentService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.YMTDateUtil;
/**
*查询小程序列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMchAppList{
	private static GetMchAppListBean getmchapplistBean;
	private static GetMchAppListCall getmchapplistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询小程序列表");
	}

	@Before
	public void caseUp() {
		getmchapplistBean=new GetMchAppListBean();
		getmchapplistCall=new GetMchAppListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmchapplistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchAppList_001() {
		Logger.start(true,"查询小程序列表");
		try {
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();			
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_002() {
		Logger.start(true,"输入mchid查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.Remark("啊哈哈", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			WxComponentService.ConfirmAuditMchApp(mchid);
			WxComponentService.AuthorizationCallBack(appid, "authorized");
			
			
			getmchapplistBean.setMchId(mchid);
			getmchapplistBean.setPageSize(1);
			getmchapplistBean.setPageIndex(1);
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();			
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("啊哈哈",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_003() {
		Logger.start(true,"输入mchName查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
            
            JsonObject getMchInfoById = GodmchManageCallService.GetMchInfoById(mchid);
			
			getmchapplistBean.setMchName(getMchInfoById.get("mchTitle").getAsString());
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();			
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("aaa",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_004() {
		Logger.start(true,"输入mobile查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
            
            JsonObject getMchInfoById = GodmchManageCallService.GetMchAppByMchId(mchid);
			
			getmchapplistBean.setMobile(getMchInfoById.get("mobile").getAsString());
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();	
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("aaa",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_005() {
		Logger.start(true,"输入mobileAreaCode查询");
		try {
			
			getmchapplistBean.setMobileAreaCode("86");
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();			
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_006() {
		Logger.start(true,"输入mchType查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
            JsonObject getMchInfoById = GodmchManageCallService.GetMchAppByMchId(mchid);
			
			getmchapplistBean.setMchType(1);
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();	
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("aaa",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_007() {
		Logger.start(true,"输入mchStatus查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
            JsonObject getMchInfoById = GodmchManageCallService.GetMchAppByMchId(mchid);
			
			getmchapplistBean.setMchStatus(1);
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();	
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("aaa",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_008() {
		Logger.start(true,"输入isPublished查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
			
            JsonObject getMchInfoById = GodmchManageCallService.GetMchAppByMchId(mchid);
			
			getmchapplistBean.setMobile(getMchInfoById.get("isPublished").getAsString());
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();	
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("aaa",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_009() {
		Logger.start(true,"输入payChannelStatus查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
			
            JsonObject getMchInfoById = GodmchManageCallService.GetMchAppByMchId(mchid);
			
			getmchapplistBean.setMobile(getMchInfoById.get("payChannelStatus").getAsString());
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();	
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("aaa",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_010() {
		Logger.start(true,"输入appStatus查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
			
            JsonObject getMchInfoById = GodmchManageCallService.GetMchAppByMchId(mchid);
			
			getmchapplistBean.setMobile(getMchInfoById.get("appStatus").getAsString());
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();	
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
			
			JsonArray asJsonArray = getmchapplistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("mchAppListVos");
			asJsonArray.forEach(b->{
				JsonObject mchAppList = b.getAsJsonObject();
				if(!mchAppList.get("mchId").isJsonNull() && mchAppList.get("mchId").getAsInt()==mchid){
					Logger.verifyEquals("1",mchAppList.get("appStatus").getAsString(),"验证app状态");
					Logger.verifyEquals("aaa",mchAppList.get("mark").getAsString(),"验证app备注");
					
				} 
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_011() {
		Logger.start(true,"分页查询");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
		
            JsonObject getMchInfoById = GodmchManageCallService.GetMchAppByMchId(mchid);
			
			getmchapplistBean.setMobile(getMchInfoById.get("appStatus").getAsString());
			getmchapplistBean.setPageSize(1);
			getmchapplistBean.setPageIndex(2);
			getmchapplistCall.setData(getmchapplistBean);
			getmchapplistCall.callService();	
			Logger.verifyEquals("200", getmchapplistCall.getString("code"), "验证返回code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_012() {
		Logger.start(true,"授权-取消授权-授权--查看状态");
		try {
			//创建小程序-授权
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            //取消授权再授权
            WxComponentService.CancelAuthorization(mchid);
            appid = WxComponentService.ConfirmAuthorization(mchid);
            JsonObject ja = GodmchManageCallService.GetMchAppAllStatus(mchid);
			Logger.verifyEquals(1,ja.get("appStatus").getAsInt(), "验证返回appStatus");
			Logger.verifyEquals("已授权",ja.get("appStatusValue").getAsString(), "验证返回appStatusValue");
			Logger.verifyEquals(0,ja.get("payChannelStatus").getAsInt(), "验证返回payChannelStatus");
			Logger.verifyEquals(0,ja.get("chargeStatus").getAsInt(), "验证返回chargeStatus");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMchAppList_013() {
		Logger.start(true,"授权-付费--取消授权-授权--查看状态");
		try {

			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            //授权
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            //付费
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.ConfirmAuditMchApp(mchid);
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
//            //取消授权-授权
			WxComponentService.CancelAuthorization(mchid);
            appid = WxComponentService.ConfirmAuthorization(mchid);
            JsonObject ja = GodmchManageCallService.GetMchAppAllStatus(mchid);
            
            Logger.verifyEquals(1,ja.get("appStatus").getAsInt(), "验证返回appStatus");
			Logger.verifyEquals("已授权",ja.get("appStatusValue").getAsString(), "验证返回appStatusValue");
			Logger.verifyEquals(0,ja.get("payChannelStatus").getAsInt(), "验证返回payChannelStatus");
			Logger.verifyEquals(1,ja.get("chargeStatus").getAsInt(), "验证返回chargeStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}